'''
爬出鹿晗微博下的粉丝的Id
'''
import re
import json
import requests

def get_html():
    i=0
    while i<=100000:
        i=i+1
        URL = "https://m.weibo.cn/api/comments/show?id=4256573775778170&page=" + str(i)
        try:
            response = requests.get(URL)
            response.raise_for_status() # 返回状态不是200 引发异常
            response.encoding =response.apparent_encoding
            m = response.json()
            for j in range(len(m['data']['data'])):
                id = m.get('data').get('data')[j].get('user').get('id')
                screen_name = m.get('data').get('data')[j].get('user').get('screen_name')
                profile_url = m.get('data').get('data')[j].get('user').get('profile_url')
                # print(screen_name,id)

                with open('luhanfensi.txt', 'a', encoding='utf-8') as f:
                    f.write('[' + screen_name + ']' + ":" + str(id) + '\n')
                    f.write(profile_url + '\n')
        except:
            return "connect error"
    print('ok!!!!')
get_html()